<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Catalog</title>
</head>
<body>
<body background="../img/bg.jpg"> 
	<font face="Berlin Sans FB Demi" color="#357EC7" size="3">
<center>
<br><br><br><br>
<h1>Administrare elevi</h1>
	<?
error_reporting (E_ALL ^ E_NOTICE);
include('auth.php');
include('../config.php');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) {die('Failed to connect to server: ' . mysql_error());}
           
$db = mysql_select_db(DB_DATABASE);
if(!$db) {die("Unable to select database");}
?>
<b>

<form action='clasa.php' method="post">
<table border="1">
<tr><td>Selectare elev: </td><td><select name="elev">
<?
$sql65=mysql_query("select nume from elev where clasa='".$_POST['clasa']."'");
while ($result555=mysql_fetch_array($sql65)) {
echo "<option>".$result555['nume']."</option>";
}
?>
</select></td></tr>
<tr><td>Selectare materie: </td><td><select name="materie">
<?
$sql=mysql_fetch_array(mysql_query("select id from profesori where nume='".$_POST['prof']."'"));
$id=$sql['id'];
$sql3=mysql_query("SELECT *,materie.nume, profesori.nume as prof
FROM clase, materie, profesori
WHERE clase.materie_id = materie.id
AND clase.profesor_id ='".$id."' and clase.nume='".$_POST['clasa']."' group by materie.nume");
while ($result1=mysql_fetch_array($sql3)){
echo "<option>".$result1['nume']."</option>";
}
?>
</select></td></tr>
<tr><td>Semestru: </td><td><select name="semestru">
<option>Semestrul I</option>
<option>Semestrul II</option>
<option>Media generala</option>
</select></td></tr>
<tr><td>Actiune: </td><td><select name="actiune">
<option>Adauga nota</option>
<option>Adauga absenta</option>
<option>Incheie media</option>
<?
$q=mysql_fetch_array(mysql_query("select dirig from profesori where id='".$_SESSION['SESS_PROF']."'"));
if ($q['dirig']==$_POST['clasa']) {
echo "<option>Afiseaza statisticile elevului</option>";
echo "<option>Motivare absente</option>";
}
?>

</select></tr></td>

<tr><td colspan="2"><center><input type="submit" value="OK"></center></tr></td>
</table>
<input type="hidden" value="<? echo $_POST['clasa']; ?>" name="clasa">
</form>
<br>
<br>
<center><h1>Statistici clasa</h1></center>
<table border="1">
<?
$id =mysql_query("select id from elev where clasa='".$_POST['clasa']."'");
while ($result=mysql_fetch_array($id)) {
	$sql=mysql_query("select abs from elev_has_materie where elev_id='".$result[0]."'");
		while ($result1=mysql_fetch_array($sql)) {
			$abs=explode("-",$result1[0]);
			if (strtolower($abs[1])=='nemotivat') {
	$i++;
} else $j++;
}
}
?>
<tr><td>Total absente nemotivate:</td><td><b><? echo $i; ?></b></td></tr>
<tr><td>Total absente motivate:</td><td><b><? echo $j; ?></b></td></tr>
<?
$elev=mysql_num_rows(mysql_query("select * from elev where clasa='".$_POST['clasa']."'"));
echo "<tr><td>Total elevi:</td><td><b>$elev</b></td></tr>";
$fete=mysql_num_rows(mysql_query("select * from elev where clasa='".$_POST['clasa']."' and sex='F'"));
$baieti=mysql_num_rows(mysql_query("select * from elev where clasa='".$_POST['clasa']."' and sex='M'"));
?>
<tr><td>Total fete:</td><td><b><? echo $fete; ?></b></td></tr>
<tr><td>Total baieti:</td><td><b><? echo $baieti; ?></b></td></tr>
</table>
<?

$idelev=mysql_fetch_array(mysql_query("select id from elev where nume='".$_POST['elev']."'"));
$matelev=mysql_fetch_array(mysql_query("select id from materie where nume='".$_POST['materie']."'"));
					
if ($semestru=='Semestrul I') $sem=1;
if ($semestru=='Semestrul II') $sem=2;
if ($semestru=='Media generala') $sem=gen;
					if ($_POST['actiune']=='Adauga nota') {

echo '<script type="text/javascript">
window.location = "addnota.php?elev='.$idelev[0].'&materie='.$matelev[0].'&sem='.$sem.'"
</script>';
}
if ($_POST['actiune']=='Adauga absenta') {
echo '<script type="text/javascript">
window.location = "addabs.php?elev='.$idelev[0].'&materie='.$matelev[0].'"
</script>';
}
if ($_POST['actiune']=='Afiseaza statisticile elevului') {
echo '<script type="text/javascript">
window.location = "show.php?elev='.$idelev[0].'"
</script>';
}
if ($_POST['actiune']=='Motivare absente') {
echo '<script type="text/javascript">
window.location = "motabs.php?elev='.$idelev[0].'&materie='.$matelev[0].'"
</script>';
}
if ($_POST['actiune']=='Incheie media') {
echo '<script type="text/javascript">
window.location = "medie.php?sem='.$sem.'&materieid='.$matelev[0].'&elevid='.$idelev[0].'"
</script>';
}
?>
</font>
</center>
</body>
</html>